<?php
namespace app\serveruser\service\user;

use \app\manage\service\ApiBase;

class User extends ApiBase
{
    protected $userValidate = '\app\serveruser\validate\User';
    protected $userLogic = '\app\serveruser\logic\User';

    /*登录*/
    public function login(): array 
    {
        //接收错误次数和检验图形验证码参数
        $data = $this->haveIssetReceiveData(['name'=>' ', 'login_password'=>' ', 'token'=>' ', 'img_type'=>'', 'img_code_id'=>0, 'auth_code'=>'', 'is_auto_login'=>0]);
        return $this->stepRun($data, 'serveruser/user/User/login,serveruser/user/User/info,serverauthcode/authcode/ApiAuthCode/verifyAuthCode', '', 'login', 1, $this->userValidate, $this->userLogic);
    }

    //用户审核
    public function passAudit(): array 
    {
        $data = $this->haveIssetReceiveData(['name'=>'', 'id'=>'', 'phone'=>'']);
        if(array_eq($data, '', ['name','id','phone'])){
            return verify_err($data, 'name,id,phone至少要传一个');
        }
        return $this->oneStepRun($data, 'serveruser/user/User/passAudit', 'passAudit');
    }

    /*用户分页列表数据*/
    public function list(): array 
    {
        $data = $this->haveIssetReceiveData(['page'=>1, 'list_rows'=>'', 'keywords'=>'', 'authen_status'=>''], []);
        return $this->oneStepRun($data, 'serveruser/user/User/list', 'list');
    }

    /*更改用户信息*/
    public function edit(): array 
    {
        $data = $this->haveIssetReceiveData(['id'=>'0', 'name'=>'', 'nickname'=>'', 'sex'=>'', 'phone'=>'', 
            'row_ids'=>'','row_group_ids'=>'','other_info'=>'']);
        return $this->oneStepRun($data, 'serveruser/user/User/edit', 'edit');
    }
    // 用户退出登录
    public function logout(): array
    {
        $data['token'] = $this->token;
        return $this->oneStepRun($data, 'serveruser/user/User/logout', 'logout');
    }
    // 用户编辑自己的信息
    public function editSelfInfo(): array
    {
        $data = $this->haveIssetReceiveData(['nickname'=>'', 'sex'=>'', 'token'=>' ']);
        if (array_eq($data, '', ['sex', 'nickname'])) {
            return verify_err($data, 'nickname,sex至少传一个参数');
        }
        return $this->oneStepRun($data, 'serveruser/user/User/editSelfInfo', 'editSelfInfo');
    }
    // 用户修改自己的登录密码
    public function editSelfLoginPassword(): array
    {
        // {"login_password":"123456789","old_login_password":"12345678","re_login_password":"123456789"}
        $data = $this->haveIssetReceiveData(['token'=>' ', 'login_password'=>'', 'old_login_password'=>'', 're_login_password'=>' ']);
        return $this->oneStepRun($data, 'serveruser/user/User/editSelfLoginPassword', 'editSelfLoginPassword');
    }
    // 用户修改自己的支付密码
    public function editSelfPayPassword(): array
    {
        $data = $this->haveIssetReceiveData(['token'=>' ', 'pay_password'=>'', 'old_pay_password'=>'', 're_pay_password'=>' ']);
        return $this->oneStepRun($data, 'serveruser/user/User/editSelfPayPassword', 'editSelfPayPassword');
    }
    // 管理员重置用户登录密码
    public function resetUserLoginPassword(): array
    {
        $setArr = ['id'=>'', 'name'=>'', 'phone'=>'', 'login_password'=>' ', 're_login_password'=>' '];
        $data = $this->haveIssetReceiveData($setArr);
        if(array_eq($data, '', ['id', 'name', 'phone'])){ 
            return verify_err(null, 'id,name,phone至少要传一个'); 
        }
        return $this->oneStepRun($data, 'serveruser/user/User/resetUserLoginPassword', 'resetUserLoginPassword');
    }
    // 管理员重置所有用户登录密码 
    public function resetAllLoginPassword(): array
    {
        $setArr = ['id'=>'', 'name'=>'', 'phone'=>'', 'login_password'=>' ', 're_login_password'=>' '];
        $data = $this->haveIssetReceiveData($setArr);
        if(array_eq($data, '', ['id', 'name', 'phone'])){ 
            return verify_err(null, 'id,name,phone至少要传一个'); 
        }
        return $this->oneStepRun($data, 'serveruser/user/User/resetAllLoginPassword', 'resetAllLoginPassword');
    }
    // 管理员重置用户支付密码
    public function resetUserPayPassword(): array
    {
        $setArr = ['id'=>'', 'name'=>'', 'phone'=>'', 'pay_password'=>' ', 're_pay_password'=>' '];
        $data = $this->haveIssetReceiveData($setArr);
        if(array_eq($data, '', ['id', 'name', 'phone'])){ 
            return verify_err(null, 'id,name,phone至少要传一个'); 
        }
        return $this->oneStepRun($data, 'serveruser/user/User/resetUserPayPassword', 'resetUserPayPassword');
    }
    // 管理员重置所有用户支付密码 
    public function resetAllPayPassword(): array
    {
        $setArr = ['id'=>'', 'name'=>'', 'phone'=>'', 'pay_password'=>' ', 're_pay_password'=>' '];
        $data = $this->haveIssetReceiveData($setArr);
        if(array_eq($data, '', ['id', 'name', 'phone'])){ 
            return verify_err(null, 'id,name,phone至少要传一个'); 
        }
        return $this->oneStepRun($data, 'serveruser/user/User/resetAllPayPassword', 'resetAllPayPassword');
    }

    /*管理员进行审核用户的实名认证信息*/
    public function verifyAuthentication(): array 
    {
        $data = $this->haveIssetReceiveData(['id'=>0, 'status'=>' ', 'token'=>' '],['']);
        return $this->oneStepRun($data, 'serveruser/user/User/verifyAuthentication', 'verifyAuthentication');
    }

    /*管理员获取实名认证列表*/
    public function getAuthticationList(): array 
    {
        $data = $this->haveIssetReceiveData(['status'=>' ', 'page'=>1, 'list_rows'=>15, 'keywords'=>''],['']);
        return $this->oneStepRun($data, 'serveruser/user/User/getAuthticationList', 'getAuthticationList');
    }

    /*根据token获取用户权限列表*/
    public function getAuthByToken(): array
    {
        $data = $this->haveIssetReceiveData(['token'=>' ']);
        return $this->oneStepRun($data, 'serveruser/auth/Token/getAuthByToken', 'getAuthByToken');
    }
    /*今周用户注册量(新增用户)/ 总用户*/
    public function userIncreTendency(): array 
    {
        $data = $this->haveIssetReceiveData(['dbDateFormat'=>'%y-%m-%d', 'dateFormat'=>'y-m-d', 'token'=>' ']);
        return $this->oneStepRun($data, 'serveruser/user/User/userIncreTendency', '');
    }
    /*根据 ID ||用户名 || 手机号 获取某一用户信息*/   
    public function info(): array 
    {
        $data = $this->haveIssetReceiveData(['id' => '', 'name' => '', 'phone' => '', 'is_add_no_user_counts' => '', 'token'=>'']);
        if($data['is_add_no_user_counts'] == 1 && !$data['token']){
            return verify_err(null, '请传入参数token');
        }
        if(array_eq($data, '', ['name','id','phone'])){
            return verify_err($data, 'name,id,phone至少要传一个');
        }
        return $this->oneStepRun($data, 'serveruser/user/User/info', '');
    }
    // 后台添加管理员
    public function addManager(): array 
    {
        $data = $this->haveIssetReceiveData(['name'=>' ','phone'=>' ', 'login_password'=>' ', 'token'=>' ']);
        return $this->stepRun($data, 'serveruser/user/User/addManager', '', 'addManager', 1, $this->userValidate, $this->userLogic);
    }
}
